#!/usr/local/bin/lua
-- Script for classifying a message read from stdin

require "osbf"

dbset = {
          classes = {"nonspam.cfc", "spam.cfc"},
          ncfs = 1,
          delimiters = ""
}
classify_flags = 0

-- read the entire message into var "text"
text = io.read("*all")

pR, p_array, i_pmax = osbf.classify(text, dbset, classify_flags)

if (pR == nil) then
   print(p_array)  -- in case of error, p_array contains the error message
else
   io.write(string.format("Score: %f - ", pR))
   if (pR >= 0) then
     io.write("HAM\n")
   else
     io.write("SPAM\n")
   end
end

